﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebSite.UserControl
{
    public partial class NavMenu : System.Web.UI.UserControl
    {
        public int SelectedIndex
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            base.PreRender+=new EventHandler(NavMenu_PreRender);
        }

        void NavMenu_PreRender(object sender, EventArgs e)
        {
            List<HtmlGenericControl> list = new List<HtmlGenericControl>();
            foreach (Control i in this.Controls)
            {
                var ctrl = i as HtmlGenericControl;
                if (ctrl == null)
                {
                    continue;
                }
                if (ctrl.TagName.ToLower() == "li")
                {
                    list.Add(ctrl);
                }
            }
            var li = list[SelectedIndex];
            li.Attributes["class"] = "cur";
            
        }
    }
}